#pragma region Licensing
/*
       LOGL::GLib -> LorgonJortle's OpenGL Game Library
       Copyright (C) 2011  Jesse 'LorgonJortle' Wilkerson

       This program is free software: you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation, either version 3 of the License, or
       (at your option) any later version.

       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.

       You should have received a copy of the GNU General Public License
       along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma endregion

#include <iostream>

#include "Exception.h"

namespace LOGL_GLib
{
     namespace Utilities
     {
          /* Scope in our static variables. */
          std::string* Exception::lastError;

          /******************************************************************************
           Exception::Exception();
                    Arguments:
                         void

                    Description:
                         Constructs an Exception object of an un-named critical error.

                    Returns:
                         The Exception object.
          *******************************************************************************/
          Exception::Exception()
          {
               std::stringstream stream;
               stream << "A critical exception occurred. -- " << what();

               message = stream.str();

               /* Set the last error. */
               *lastError = message;
          }

          /******************************************************************************
           Exception::Exception(const std::string& _Message);
                    Arguments:
                         const std::string& _Message:
                              The reason for the exception.

                    Description:
                         Constructs a specified Exception object.

                    Returns:
                         The Exception object.
          *******************************************************************************/
          Exception::Exception(const std::string& _Message)
          {
               std::stringstream stream;
               stream << _Message << " -- " << std::exception::what();

               message = stream.str();

               /* Set the last error. */
               *lastError = message;
          }

          /******************************************************************************
           Exception::Exception(const std::exception& _Exception);
                    Arguments:
                         const std::exception& _Exception:
                              An exception to handle.

                    Description:
                         Constructs an exception based off another.

                    Returns:
                         The Exception object.
          *******************************************************************************/
          Exception::Exception(const std::exception& _Exception)
          {
               std::stringstream stream;
               stream << "A critical exception occurred. -- " << std::exception::what();

               message = stream.str();

               /* Set the last error. */
               *lastError = message;
          }

          /******************************************************************************
           Exception::~Exception() throw();
                    Arguments:
                         void

                    Description:
                         Destroys the exception.

                    Returns:
                         void
          *******************************************************************************/
          Exception::~Exception() throw()
          {

          }

          /******************************************************************************
           static GLvoid Exception::Initialize(std::string& _LastError);
                    Arguments:
                         std::string& _LastError:
                              A reference the the game's last error.

                    Description:
                         Initializes exception handling.

                    Returns:
                         void
          *******************************************************************************/
          GLvoid Exception::Initialize(std::string* _LastError)
          {
               lastError =_LastError;
          }

          /******************************************************************************
           std::string Exception::Message() const;
                    Arguments:
                         void

                    Description:
                         Gets the message associated with the exception.

                    Returns:
                         The message associated with the exception.
          *******************************************************************************/
          std::string Exception::Message() const
          {
               return message;
          }

          /******************************************************************************
           virtual const GLchar* Exception::what() const throw();
                    Arguments:
                         void

                    Description:
                         Gets the message associated with the exception.

                    Returns:
                         The message associated with the exception.
          *******************************************************************************/
          const GLchar* Exception::what() const throw()
          {
               return message.c_str();
          }

     } /* Namespace Utilities. */
} /* Namespace LOGL_GLib. */
